﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using DualityEngine.Business;

namespace DualityClient.MenuComponents.Buttons
{
    public class Button : GuiControl
    {
        private Texture2D hovercontrolbackground;
        private bool isselected = false;
        private MouseState currentmousestate;

        public Button(Texture2D controlbackground, Texture2D hovercontrolbackground, Vector2 position)
        {
            this.controlbackground = controlbackground;
            this.position = position;
            this.hovercontrolbackground = hovercontrolbackground;
        }

        public override void Update(GameTime gameTime)
        {
            MouseState oldmousestate = currentmousestate;
            currentmousestate = Mouse.GetState();

            if (currentmousestate.LeftButton == ButtonState.Released && oldmousestate.LeftButton == ButtonState.Pressed && isselected == true)
            {
                Action();
            }
        }

        public override void Draw(GameTime gameTime)
        {
            if(isHovering())
            {
                ResourceManager.Instance.spriteBatch.Draw(hovercontrolbackground, position, Color.White);
                isselected = true;
            }
            else
            {
                ResourceManager.Instance.spriteBatch.Draw(controlbackground, position, Color.White);
                isselected = false;
            }
        }

        public virtual void Action()
        {
        }
    }
}
